import dva from 'dva';
import 'moment/locale/zh-cn';
import browserHistory from 'history/createBrowserHistory';
import createLoading from 'dva-loading';
import model from './models/global';
import router from './router';
import {message, notification} from 'antd';

import './index.less';

message.config({
  top: 24,
  duration: 1,
  maxCount: 3,
});

notification.config({
  placement: 'topRight',
  top: 24,
  duration: 3,
});

// 1. Initialize
const app = dva({
  history: browserHistory(),
  onError: (e) => {             // https://github.com/dvajs/dva-knowledgemap#%E7%BB%9F%E4%B8%80%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86
    e.preventDefault();
    // message.error(e.message);
    notification.error({
      message: e.name,
      description: e.message,
    });
  },
});

// 2. Plugins
app.use(createLoading());

// 3. Register global model
app.model(model);

// 4. Router
app.router(router);

// 5. Start
app.start('#root');
